package self.hoy.demo.rabbitmq.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import self.hoy.demo.rabbitmq.Constant;
import self.hoy.demo.rabbitmq.util.ConnectionUtils;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import static self.hoy.demo.rabbitmq.Constant.QUEUE_NAME;

/**
 * @author hyh
 * @date 2020/6/7
 */
public class Send implements Constant {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtils.getConnection();
        Channel channel = connection.createChannel();
        boolean durable = false;//是否持久化，已声明过的队列不能改这个值
        boolean exclusive = false;//是否专用的
        boolean autoDelete = false;//是否发完即删
        channel.queueDeclare(QUEUE_NAME, durable, exclusive, autoDelete, null);
        String msg = "Hello World From Simple! " + System.currentTimeMillis();
        channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());

        System.out.println(" ---- send message : " + msg);
        channel.close();;
        connection.close();
    }
}
